package cn.hchaojie.camp.week1.qa;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class Ex11SumDigits {
	private static final int[] DATA = {
		12345, 10001, 2005, 210381
	};
	
	@Test
	public void verify() {
		assertEquals(sumDigits(DATA[0]), 15);
		assertEquals(sumDigits(DATA[1]), 2);
		assertEquals(sumDigits(DATA[2]), 7);
		assertEquals(sumDigits(DATA[3]), 15);
	}
	
	public static int sumDigits(long n) {
		int sum = 0;
		
		while (n > 0) {
			int num = (int) (n % 10);
			sum += num;
			
			n /= 10;
		}
		
		return sum;
	}
}
